package com.li.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.drug.entity.Problem;
import com.li.drug.mapper.ProblemMapper;
import com.li.drug.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

/**
 * 问题药品service实现类
 */
@Service
public class ProblemServiceImpl extends ServiceImpl<ProblemMapper, Problem> implements ProblemService {

    @Autowired
    ProblemMapper problemMapper;

    /**
     * 分页查询问题药品数据
     * @param pageNum 第几页
     * @param pageSize 每页多少条数据
     * @param param 查询参数 - 药品名称
     * @return
     */
    @Override
    public Page<Problem> selectProblemPage(int pageNum, int pageSize, String param) {
        //构建查询条件
        QueryWrapper<Problem> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        //构建分页查询对象
        Page<Problem> page = new Page<>(pageNum,pageSize);
        return problemMapper.selectPage(page,wrapper);
    }

    @Override
    public int addProblem(Problem problem) {
        return problemMapper.insert(problem);
    }

    @Override
    public int editProblem(Problem problem) {
        return problemMapper.updateById(problem);
    }

    @Override
    public Problem getProblemById(Integer id) {
        return problemMapper.selectById(id);
    }

    @Override
    public int delProblemById(Integer id) {
        return problemMapper.deleteById(id);
    }
}
